<!DOCTYPE html>
<html>
<head>
<meta http-equiv="content-type" content="text/html; charset=UTF-8" />
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta http-equiv="Expires" CONTENT="0">
<meta http-equiv="Cache-Control" CONTENT="no-cache">
<meta http-equiv="Pragma" CONTENT="no-cache">
<title>货品</title>
<link rel="stylesheet" type="text/css" href="../easyui/themes/default/easyui.css">
<link rel="stylesheet" type="text/css" href="../easyui/themes/icon.css">
<link rel="stylesheet" type="text/css" href="../easyui/demo/demo.css">
<script type="text/javascript" src="../easyui/jquery.min.js"></script>
<script type="text/javascript" src="../easyui/jquery.easyui.min.js"></script>
<script type="text/javascript" src="../uploadjs/vendor/jquery.ui.widget.js"></script>
<script type="text/javascript" src="../uploadjs/jquery.iframe-transport.js"></script>
<script type="text/javascript" src="../uploadjs/jquery.fileupload.js"></script>
<script type="text/javascript" src="../js/auth.js"></script>
</head>
<body class="easyui-layout">
<div data-options="region:'north',border:false" style="height:100px;background:#B3DFDA;padding:10px">
<div style="float:right;clear:both;margin-top:15px;margin-right:20px">
    <a href="javascript:logout()">注销</a>
    </div>
    <h2>蛋糕商城</h2>
    <h3>从2025为公众服务</h3>
</div>
<div data-options="region:'west',split:true,title:'主菜单'" style="width:180px;padding:0px;">
<div onclick="window.location='../pages/index.html'" class="menu-item" style="height: 20px;"><div class="menu-text" style="height: 20px; line-height: 20px;">主页</div><div class="menu-icon icon-add"></div></div>
<div onclick="window.location='../admin/index'" class="menu-item" style="height: 20px;"><div class="menu-text" style="height: 20px; line-height: 20px;">蛋糕商城后台</div><div class="menu-icon icon-add"></div></div>
<div onclick="window.location='../pages/goodses.html'" class="menu-item" style="height: 20px;"><div class="menu-text" style="height: 20px; line-height: 20px;">货品</div><div class="menu-icon icon-add"></div></div>
<div onclick="window.location='../pages/custorders.html'" class="menu-item" style="height: 20px;"><div class="menu-text" style="height: 20px; line-height: 20px;">订单</div><div class="menu-icon icon-add"></div></div>
<div onclick="window.location='../pages/orderitems.html'" class="menu-item" style="height: 20px;"><div class="menu-text" style="height: 20px; line-height: 20px;">订单项</div><div class="menu-icon icon-add"></div></div>
<div onclick="window.location='../pages/recommends.html'" class="menu-item" style="height: 20px;"><div class="menu-text" style="height: 20px; line-height: 20px;">推荐</div><div class="menu-icon icon-add"></div></div>
<div onclick="window.location='../pages/types.html'" class="menu-item" style="height: 20px;"><div class="menu-text" style="height: 20px; line-height: 20px;">类型</div><div class="menu-icon icon-add"></div></div>
<div onclick="window.location='../pages/roles.html'" class="menu-item" style="height: 20px;"><div class="menu-text" style="height: 20px; line-height: 20px;">角色</div><div class="menu-icon icon-add"></div></div>
<div onclick="window.location='../pages/permissions.html'" class="menu-item" style="height: 20px;"><div class="menu-text" style="height: 20px; line-height: 20px;">许可</div><div class="menu-icon icon-add"></div></div>
<div onclick="window.location='../pages/users.html'" class="menu-item" style="height: 20px;"><div class="menu-text" style="height: 20px; line-height: 20px;">用户</div><div class="menu-icon icon-add"></div></div>
<div onclick="window.location='../pages/profile.html'" class="menu-item" style="height: 20px;"><div class="menu-text" style="height: 20px; line-height: 20px;">用户资料</div><div class="menu-icon icon-add"></div></div>
<div onclick="window.location='../pages/linkcustorderorderitem.html'" class="menu-item" style="height: 20px;"><div class="menu-text" style="height: 20px; line-height: 20px;">链接订单订单项</div><div class="menu-icon icon-add"></div></div>
<div onclick="window.location='../pages/linkrolepermission.html'" class="menu-item" style="height: 20px;"><div class="menu-text" style="height: 20px; line-height: 20px;">链接角色许可</div><div class="menu-icon icon-add"></div></div>
<div onclick="window.location='../pages/linkuserrole.html'" class="menu-item" style="height: 20px;"><div class="menu-text" style="height: 20px; line-height: 20px;">链接用户角色</div><div class="menu-icon icon-add"></div></div>
</div>
<div data-options="region:'east',split:true,collapsed:true,title:'属性'" style="width:250px;overflow: hidden">
</div>
<div data-options="region:'south',border:false" style="height:40px;background:#A9FACD;padding:10px;text-align: center">
    蛋糕商城
</div>
<div data-options="region:'center',title:'第三代动词算子式代码生成器：光　生成结果'">
<div title="搜索面板" class="easyui-panel" style="width:1600px;height:200px">
<form id="ffsearch" method="post">
<table cellpadding="5">
<tr>
<td>名字:</td><td><input  class='easyui-textbox' type='text' name='name' id='name' value='' data-options="required:false"/></td>
<td>活跃:</td><td><input  class='easyui-textbox' type='text' name='active' id='active' value='' data-options="required:false"/></td>
<td>价格:</td><td><input  class='easyui-textbox' type='text' name='price' id='price' value='' data-options="required:false"/></td>
<td>
        <select id="actionSelect" class='easyui-select' style="	width:90px;height:28px" onchange="toggleBtnShow(this.value)">
            <option value="1" selected>搜索</option>
            <option value="2">Excel过滤</option>
            <option value="3">PDF过滤</option>
            <option value="4">Word过滤</option>
            <option value="5">PPT过滤</option>
        </select>
        </td><td>
        <div id="button-bar">
            <a href="#" class="easyui-linkbutton" style="display:block;width:110px;height:28px" data-options="iconCls:'icon-search'" onclick="searchGoodsesByFieldsByPage()">搜索</a>
            <a href="#" class="easyui-linkbutton" style="display:none;width:110px;height:28px" data-options="iconCls:'icon-filter'" onclick="filterGoodsesExcel()">Excel过滤</a>
            <a href="#" class="easyui-linkbutton" style="display:none;width:110px;height:28px" data-options="iconCls:'icon-filter'" onclick="filterGoodsesPDF()"">PDF过滤</a>
            <a href="#" class="easyui-linkbutton" style="display:none;width:110px;height:28px" data-options="iconCls:'icon-filter'" onclick="filterGoodsesWord()"">Word过滤</a>
            <a href="#" class="easyui-linkbutton" style="display:none;width:110px;height:28px" data-options="iconCls:'icon-filter'" onclick="filterPPTGoodses()"">PPT过滤</a>
        </div>
        </td><td>
            <a href="javascript:void(0)" class="easyui-linkbutton" style="width:80px" data-options="iconCls:'icon-clear'"  onclick="clearForm('ffsearch');toggleBtnShow(1);$('#actionSelect').val(1)">清除</a>
</td>
</tr>
<tr>
<td>简介:</td><td><input  class='easyui-textbox' type='text' name='intro' id='intro' value='' data-options="required:false"/></td>
<td>存货:</td><td><input  class='easyui-textbox' type='text' name='stock' id='stock' value='' data-options="required:false"/></td>
<td>类型:</td><td><input  class='easyui-combobox' type='text' name='type' id='type' value='' data-options="required:false,valueField:'id',textField:'name',method:'post',url:'../typeController/listActiveTypes',loadFilter:function(data){return data.rows}"/></td>
<td></td><td colspan='3'></td>
</tr>
<tr>
<td>滚动:</td><td><input  class='easyui-textbox' type='text' name='isScroll' id='isScroll' value='' data-options="required:false"/></td>
<td>热门商品:</td><td><input  class='easyui-textbox' type='text' name='isHot' id='isHot' value='' data-options="required:false"/></td>
<td>等级:</td><td><input  class='easyui-textbox' type='text' name='isNew' id='isNew' value='' data-options="required:false"/></td>
<td></td><td colspan='3'></td>
</tr>
</table>
</form>
</div>
<table id="dg" class="easyui-datagrid" title="货品清单" style="width:1600px;height:600px" data-options="singleSelect:false,url:'../goodsController/searchGoodsesByFieldsByPage',queryParams:params,method:'post',pagination:true,toolbar:toolbar">
<thead>
<tr>
<th data-options="field:'id',checkbox:true">序号</th>
<th data-options="field:'name',width:80">名字</th>
<th data-options="field:'active',width:80">活跃</th>
<th data-options="field:'cover',width:140,formatter:showGoodsCoverImage">封面</th>
<th data-options="field:'image1',width:140,formatter:showGoodsImage1Image">图片一</th>
<th data-options="field:'image2',width:140,formatter:showGoodsImage2Image">图片二</th>
<th data-options="field:'price',width:80">价格</th>
<th data-options="field:'intro',width:80">简介</th>
<th data-options="field:'stock',width:80">存货</th>
<th data-options="field:'type',width:80,formatter:translateType">类型</th>
<th data-options="field:'isScroll',width:80">滚动</th>
<th data-options="field:'isHot',width:80">热门商品</th>
<th data-options="field:'isNew',width:80">等级</th>
</tr>
</thead>
</table>
<div class="easyui-window" title="新增货品" id="waddGoods" data-options="iconCls:'icon-save',modal:true,closed:true" style="width:800px;height:600px">
<div style="padding:10px 60px 20px 60px">
<form id="ff" method="post">
<table cellpadding="5">
<tr><td>名字:</td><td><input  class='easyui-textbox' type='text' name='name' id='name' value='' data-options="required:false"/></td></tr>
<tr><td>封面:</td><td><img name='cover' id='cover' width='500px' src='../images/blank.jpg'><br>
<input id="addGoodsCoverFileupload" type="file" name="files[]" data-url="../goodsController/addUploadGoodsCover"><br></td></tr>
<tr><td>图片一:</td><td><img name='image1' id='image1' width='500px' src='../images/blank.jpg'><br>
<input id="addGoodsImage1Fileupload" type="file" name="files[]" data-url="../goodsController/addUploadGoodsImage1"><br></td></tr>
<tr><td>图片二:</td><td><img name='image2' id='image2' width='500px' src='../images/blank.jpg'><br>
<input id="addGoodsImage2Fileupload" type="file" name="files[]" data-url="../goodsController/addUploadGoodsImage2"><br></td></tr>
<tr><td>价格:</td><td><input  class='easyui-textbox' type='text' name='price' id='price' value='' data-options="required:false"/></td></tr>
<tr><td>简介:</td><td><input  class='easyui-textbox' type='text' name='intro' id='intro' value='' data-options="required:false"/></td></tr>
<tr><td>存货:</td><td><input  class='easyui-textbox' type='text' name='stock' id='stock' value='' data-options="required:false"/></td></tr>
<tr><td>类型:</td><td><input  class='easyui-combobox' type='text' name='type' id='type' value='' data-options="required:false,valueField:'id',textField:'name',method:'post',url:'../typeController/listActiveTypes',loadFilter:function(data){return data.rows}"/></td></tr>
<tr><td>滚动:</td><td><input  class='easyui-textbox' type='text' name='isScroll' id='isScroll' value='' data-options="required:false"/></td></tr>
<tr><td>热门商品:</td><td><input  class='easyui-textbox' type='text' name='isHot' id='isHot' value='' data-options="required:false"/></td></tr>
<tr><td>等级:</td><td><input  class='easyui-textbox' type='text' name='isNew' id='isNew' value='' data-options="required:false"/></td></tr>
<tr><td>活跃:</td><td><input class='easyui-radio' type='radio' name='active' id='active' value='true' checked='true'/>True<input type='radio' class='easyui-radio' name='active' id='active' value='false'/>False</td></tr>
</table>
</form>
<div style="text-align:center;padding:5px">
<a href="javascript:void(0)" class="easyui-linkbutton" onclick="addGoods()">新增</a>
<a href="javascript:void(0)" class="easyui-linkbutton" onclick="clearForm('ff')">清除</a>
<a href="javascript:void(0)" class="easyui-linkbutton" onclick="$('#waddGoods').window('close')">取消</a>
</div>
</div>
<div class="easyui-window" title="编辑货品" id="wupdateGoods" data-options="iconCls:'icon-save',modal:true,closed:true" style="width:800px;height:600px">
<div style="padding:10px 60px 20px 60px">
<form id="ffedit" method="post">
<input  type='hidden' name='id' id='id' value=''/>
<table cellpadding="5">
<tr><td>名字:</td><td><input  class='easyui-textbox' type='text' name='name' id='name' value='' data-options="required:false"/></td></tr>
<tr><td>封面:</td><td><img name='cover' id='cover' width='500px' src='../images/blank.jpg'><br>
<input id="goodsCoverFileupload" type="file" name="files[]" data-url="../goodsController/addUploadGoodsCover"><br></td></tr>
<tr><td>图片一:</td><td><img name='image1' id='image1' width='500px' src='../images/blank.jpg'><br>
<input id="goodsImage1Fileupload" type="file" name="files[]" data-url="../goodsController/addUploadGoodsImage1"><br></td></tr>
<tr><td>图片二:</td><td><img name='image2' id='image2' width='500px' src='../images/blank.jpg'><br>
<input id="goodsImage2Fileupload" type="file" name="files[]" data-url="../goodsController/addUploadGoodsImage2"><br></td></tr>
<tr><td>价格:</td><td><input  class='easyui-textbox' type='text' name='price' id='price' value='' data-options="required:false"/></td></tr>
<tr><td>简介:</td><td><input  class='easyui-textbox' type='text' name='intro' id='intro' value='' data-options="required:false"/></td></tr>
<tr><td>存货:</td><td><input  class='easyui-textbox' type='text' name='stock' id='stock' value='' data-options="required:false"/></td></tr>
<tr><td>类型:</td><td><input  class='easyui-combobox' type='text' name='type' id='type' value='' data-options="required:false,valueField:'id',textField:'name',method:'post',url:'../typeController/listActiveTypes',loadFilter:function(data){return data.rows}"/></td></tr>
<tr><td>滚动:</td><td><input  class='easyui-textbox' type='text' name='isScroll' id='isScroll' value='' data-options="required:false"/></td></tr>
<tr><td>热门商品:</td><td><input  class='easyui-textbox' type='text' name='isHot' id='isHot' value='' data-options="required:false"/></td></tr>
<tr><td>等级:</td><td><input  class='easyui-textbox' type='text' name='isNew' id='isNew' value='' data-options="required:false"/></td></tr>
<tr><td>活跃:</td><td><input class='easyui-radio' type='radio' name='active' id='active' value='true' checked='true'/>True<input type='radio' class='easyui-radio' name='active' id='active' value='false'/>False</td></tr>
</table>
</form>
<div style="text-align:center;padding:5px">
<a href="javascript:void(0)" class="easyui-linkbutton" onclick="updateGoods()">编辑</a>
<a href="javascript:void(0)" class="easyui-linkbutton" onclick="$('#ffedit').form('clear');">清除</a>
<a href="javascript:void(0)" class="easyui-linkbutton" onclick="$('#wupdateGoods').window('close')">取消</a>
</div>
</div>
<div class="easyui-window" title="查看货品" id="wviewGoods" data-options="iconCls:'icon-save',modal:true,closed:true" style="width:800px;height:600px">
<div style="padding:10px 60px 20px 60px">
<form id="ffview" method="post">
<input  type='hidden' name='id' id='id' value=''/>
<table cellpadding="5">
<tr><td>名字:</td><td><input  class='easyui-textbox' type='text' name='name' id='name' value='' data-options="required:false"/></td></tr>
<tr><td>封面:</td><td><img name='cover' id='cover' width='500px' src='../images/blank.jpg'><br>
<tr><td>图片一:</td><td><img name='image1' id='image1' width='500px' src='../images/blank.jpg'><br>
<tr><td>图片二:</td><td><img name='image2' id='image2' width='500px' src='../images/blank.jpg'><br>
<tr><td>价格:</td><td><input  class='easyui-textbox' type='text' name='price' id='price' value='' data-options="required:false"/></td></tr>
<tr><td>简介:</td><td><input  class='easyui-textbox' type='text' name='intro' id='intro' value='' data-options="required:false"/></td></tr>
<tr><td>存货:</td><td><input  class='easyui-textbox' type='text' name='stock' id='stock' value='' data-options="required:false"/></td></tr>
<tr><td>类型:</td><td><input  class='easyui-combobox' type='text' name='type' id='type' value='' data-options="required:false,valueField:'id',textField:'name',method:'post',url:'../typeController/listActiveTypes',loadFilter:function(data){return data.rows}"/></td></tr>
<tr><td>滚动:</td><td><input  class='easyui-textbox' type='text' name='isScroll' id='isScroll' value='' data-options="required:false"/></td></tr>
<tr><td>热门商品:</td><td><input  class='easyui-textbox' type='text' name='isHot' id='isHot' value='' data-options="required:false"/></td></tr>
<tr><td>等级:</td><td><input  class='easyui-textbox' type='text' name='isNew' id='isNew' value='' data-options="required:false"/></td></tr>
<tr><td>活跃:</td><td><input class='easyui-radio' type='radio' name='active' id='active' value='true' checked='true'/>True<input type='radio' class='easyui-radio' name='active' id='active' value='false'/>False</td></tr>
</table>
</form>
<div style="text-align:center;padding:5px">
<a href="javascript:void(0)" class="easyui-linkbutton" onclick="$('#wviewGoods').window('close')">关闭</a>
</div>
</div>
</div>
</body>
<script type="text/javascript">
var params = {};
var pagesize = 10;
var pagenum = 1;
$(function () {
    $('#addGoodsCoverFileupload').fileupload({
            autoUpload: true,
            dataType: 'json',
            async: false,
            success: function(data, textStatus) {
            if (data.success == true){
                $("#ff").find("#cover").prop("src","data:image/png;base64,"+data.data)
            }
            },
            progressall: function (e, data) {
                var progress = parseInt(data.loaded / data.total * 100, 10);
            },
        });
    $('#addGoodsImage1Fileupload').fileupload({
            autoUpload: true,
            dataType: 'json',
            async: false,
            success: function(data, textStatus) {
            if (data.success == true){
                $("#ff").find("#image1").prop("src","data:image/png;base64,"+data.data)
            }
            },
            progressall: function (e, data) {
                var progress = parseInt(data.loaded / data.total * 100, 10);
            },
        });
    $('#addGoodsImage2Fileupload').fileupload({
            autoUpload: true,
            dataType: 'json',
            async: false,
            success: function(data, textStatus) {
            if (data.success == true){
                $("#ff").find("#image2").prop("src","data:image/png;base64,"+data.data)
            }
            },
            progressall: function (e, data) {
                var progress = parseInt(data.loaded / data.total * 100, 10);
            },
        });
$('#goodsCoverFileupload').fileupload({
        autoUpload: true,
        dataType: 'json',
        async: false,
        formData : function() {
            return [{name:"id",value:$("#ffedit").find("#id").val()}
                ];
        },
        success: function(data, textStatus) {
        if (data.success == true){
            $("#ffedit").find("#cover").prop("src","data:image/png;base64,"+data.data)
        }
        },
    progressall: function (e, data) {
    var progress = parseInt(data.loaded / data.total * 100, 10);
    },
});
$('#goodsImage1Fileupload').fileupload({
        autoUpload: true,
        dataType: 'json',
        async: false,
        formData : function() {
            return [{name:"id",value:$("#ffedit").find("#id").val()}
                ];
        },
        success: function(data, textStatus) {
        if (data.success == true){
            $("#ffedit").find("#image1").prop("src","data:image/png;base64,"+data.data)
        }
        },
    progressall: function (e, data) {
    var progress = parseInt(data.loaded / data.total * 100, 10);
    },
});
$('#goodsImage2Fileupload').fileupload({
        autoUpload: true,
        dataType: 'json',
        async: false,
        formData : function() {
            return [{name:"id",value:$("#ffedit").find("#id").val()}
                ];
        },
        success: function(data, textStatus) {
        if (data.success == true){
            $("#ffedit").find("#image2").prop("src","data:image/png;base64,"+data.data)
        }
        },
    progressall: function (e, data) {
    var progress = parseInt(data.loaded / data.total * 100, 10);
    },
});
});
var toolbar = [
{
    text:'查看',
    iconCls:'icon-search',
    handler:function(){ 
        var rows = $("#dg").datagrid("getChecked");
        if (rows == undefined || rows == null || rows.length == 0 ){
            $.messager.alert("警告","请选定一条记录！","warning");
            return;
        }
        if (rows.length > 1) {
            $.messager.alert("警告","请选定一条记录！","warning");
            return;
        }
        $("#ffview").find("#id").val(rows[0]["id"]);
        $("#ffview").find("#name").textbox("setValue",rows[0]["name"]);
        if (!isBlank(rows[0]["cover"]))	{
            $("#ffview").find("#cover").prop("src","data:image/png;base64,"+rows[0]["cover"]);
        }else{
            $("#ffview").find("#cover").prop("src","../images/blank.jpg");
        }
        if (!isBlank(rows[0]["image1"]))	{
            $("#ffview").find("#image1").prop("src","data:image/png;base64,"+rows[0]["image1"]);
        }else{
            $("#ffview").find("#image1").prop("src","../images/blank.jpg");
        }
        if (!isBlank(rows[0]["image2"]))	{
            $("#ffview").find("#image2").prop("src","data:image/png;base64,"+rows[0]["image2"]);
        }else{
            $("#ffview").find("#image2").prop("src","../images/blank.jpg");
        }
        $("#ffview").find("#price").textbox("setValue",rows[0]["price"]);
        $("#ffview").find("#intro").textbox("setValue",rows[0]["intro"]);
        $("#ffview").find("#stock").textbox("setValue",rows[0]["stock"]);
        $("#ffview").find("#type").combobox("setValue",rows[0]["type"]);
        var isScrollCheckboxs = $("#ffview").find("input[name='isScroll']");
        for (var i=0;i<isScrollCheckboxs.length;i++){
            if (isScrollCheckboxs.get(i).value == ""+rows[0]["isScroll"]) isScrollCheckboxs.get(i).checked=true;
        }
        var isHotCheckboxs = $("#ffview").find("input[name='isHot']");
        for (var i=0;i<isHotCheckboxs.length;i++){
            if (isHotCheckboxs.get(i).value == ""+rows[0]["isHot"]) isHotCheckboxs.get(i).checked=true;
        }
        var isNewCheckboxs = $("#ffview").find("input[name='isNew']");
        for (var i=0;i<isNewCheckboxs.length;i++){
            if (isNewCheckboxs.get(i).value == ""+rows[0]["isNew"]) isNewCheckboxs.get(i).checked=true;
        }
        var checkboxs = $("#ffview").find("input[name='active']");
        for (var i=0;i<checkboxs.length;i++){
            if (checkboxs.get(i).value == ""+rows[0]["active"]) checkboxs.get(i).checked=true;
        }
        $('#wviewGoods').window('open');
    }
}
,
{
    text:'新增',
    iconCls:'icon-add',
    handler:function(){
        $('#waddGoods').window('open');
    }
}
,
{
    text:'编辑',
    iconCls:'icon-edit',
    handler:function(){ 
        var rows = $("#dg").datagrid("getChecked");
        if (rows == undefined || rows == null || rows.length == 0 ){
            $.messager.alert("警告","请选定一条记录！","warning");
            return;
        }
        if (rows.length > 1) {
            $.messager.alert("警告","请选定一条记录！","warning");
            return;
        }
        $("#ffedit").find("#id").val(rows[0]["id"]);
        $("#ffedit").find("#name").textbox("setValue",rows[0]["name"]);
        if (!isBlank(rows[0]["cover"]))	{
            $("#ffedit").find("#cover").prop("src","data:image/png;base64,"+rows[0]["cover"]);
        }else{
            $("#ffedit").find("#cover").prop("src","../images/blank.jpg");
        }
        if (!isBlank(rows[0]["image1"]))	{
            $("#ffedit").find("#image1").prop("src","data:image/png;base64,"+rows[0]["image1"]);
        }else{
            $("#ffedit").find("#image1").prop("src","../images/blank.jpg");
        }
        if (!isBlank(rows[0]["image2"]))	{
            $("#ffedit").find("#image2").prop("src","data:image/png;base64,"+rows[0]["image2"]);
        }else{
            $("#ffedit").find("#image2").prop("src","../images/blank.jpg");
        }
        $("#ffedit").find("#price").textbox("setValue",rows[0]["price"]);
        $("#ffedit").find("#intro").textbox("setValue",rows[0]["intro"]);
        $("#ffedit").find("#stock").textbox("setValue",rows[0]["stock"]);
        $("#ffedit").find("#type").combobox("setValue",rows[0]["type"]);
        var isScrollCheckboxs = $("#ffedit").find("input[name='isScroll']");
        for (var i=0;i<isScrollCheckboxs.length;i++){
            if (isScrollCheckboxs.get(i).value == ""+rows[0]["isScroll"]) isScrollCheckboxs.get(i).checked=true;
        }
        var isHotCheckboxs = $("#ffedit").find("input[name='isHot']");
        for (var i=0;i<isHotCheckboxs.length;i++){
            if (isHotCheckboxs.get(i).value == ""+rows[0]["isHot"]) isHotCheckboxs.get(i).checked=true;
        }
        var isNewCheckboxs = $("#ffedit").find("input[name='isNew']");
        for (var i=0;i<isNewCheckboxs.length;i++){
            if (isNewCheckboxs.get(i).value == ""+rows[0]["isNew"]) isNewCheckboxs.get(i).checked=true;
        }
        var checkboxs = $("#ffedit").find("input[name='active']");
        for (var i=0;i<checkboxs.length;i++){
            if (checkboxs.get(i).value == ""+rows[0]["active"]) checkboxs.get(i).checked=true;
        }
        $('#wupdateGoods').window('open');
    }
}
,
{
    text:'软删除',
    iconCls:'icon-remove',
    handler:function(){ 
        var rows = $("#dg").datagrid("getChecked");
        if (rows == undefined || rows == null || rows.length == 0 ){
            $.messager.alert("警告","请选定一条记录！","warning");
            return;
        }
        if (rows.length > 1) {
            $.messager.alert("警告","请选定一条记录！","warning");
            return;
        }
        var id = rows[0]["id"];
        softDeleteGoods(id);
    }
}
,
{
    text:'激活',
    iconCls:'icon-tip',
    handler:function(){ 
        var rows = $("#dg").datagrid("getChecked");
        if (rows == undefined || rows == null || rows.length == 0 ){
            $.messager.alert("警告","请选定一条记录！","warning");
            return;
        }
        if (rows.length > 1) {
            $.messager.alert("警告","请选定一条记录！","warning");
            return;
        }
        var id = rows[0]["id"];
        activateGoods(id);
    }
}
,
{
    text:'克隆',
    iconCls:'icon-add',
    handler:function(){ 
        var rows = $("#dg").datagrid("getChecked");
        if (rows == undefined || rows == null || rows.length == 0 ){
            $.messager.alert("警告","请选定一条记录！","warning");
            return;
        }
        if (rows.length > 1) {
            $.messager.alert("警告","请选定一条记录！","warning");
            return;
        }
        var id = rows[0]["id"];
        cloneGoods(id);
    }
}
,
{
    text:'删除',
    iconCls:'icon-remove',
    handler:function(){
        var rows = $("#dg").datagrid("getChecked");
        if (rows == undefined || rows == null || rows.length == 0 ){
            $.messager.alert("警告","请选定一条记录！","warning");
            return;
        }
        if ($.messager.confirm("警告","确认要删除选定记录吗？", function(data){
            if (data){
                if (rows.length > 1) {
                    $.messager.alert("警告","请选定一条记录！","warning");
                    return;
                }
                var id = rows[0]["id"];
                deleteGoods(id);
            }
        }));
}
}
,
{
    text:'切换',
    iconCls:'icon-cut',
    handler:function(){ 
        var rows = $("#dg").datagrid("getChecked");
        if (rows == undefined || rows == null || rows.length == 0 ){
            $.messager.alert("警告","请选定一条记录！","warning");
            return;
        }
        if (rows.length > 1) {
            $.messager.alert("警告","请选定一条记录！","warning");
            return;
        }
        var id = rows[0]["id"];
        toggleGoods(id);
    }
}
,
{
    text:'留一切换',
    iconCls:'icon-cut',
    handler:function(){ 
        var rows = $("#dg").datagrid("getChecked");
        if (rows == undefined || rows == null || rows.length == 0 ){
            $.messager.alert("警告","请选定一条记录！","warning");
            return;
        }
        if (rows.length > 1) {
            $.messager.alert("警告","请选定一条记录！","warning");
            return;
        }
        var id = rows[0]["id"];
        toggleOneGoods(id);
    }
}
,'-',
{
    text:'批软删除',
    iconCls:'icon-remove',
    handler:function(){ 
        var rows = $("#dg").datagrid("getChecked");
        if (rows == undefined || rows == null || rows.length == 0 ){
            $.messager.alert("警告","请选定记录！","warning");
            return;
        }
        var ids = "";
        for(var i=0;i<rows.length;i++){
            ids += rows[i]["id"];
            if (i < rows.length-1) ids += ",";
        }
        softDeleteAllGoodses(ids);
    }
}
,
{
    text:'批激活',
    iconCls:'icon-tip',
    handler:function(){ 
        var rows = $("#dg").datagrid("getChecked");
        if (rows == undefined || rows == null || rows.length == 0 ){
            $.messager.alert("警告","请选定记录！","warning");
            return;
        }
        var ids = "";
        for(var i=0;i<rows.length;i++){
            ids += rows[i]["id"];
            if (i < rows.length-1) ids += ",";
        }
        activateAllGoodses(ids);
    }
}
,
{
    text:'批克隆',
    iconCls:'icon-add',
    handler:function(){ 
        var rows = $("#dg").datagrid("getChecked");
        if (rows == undefined || rows == null || rows.length == 0 ){
            $.messager.alert("警告","请选定记录！","warning");
            return;
        }
        var ids = "";
        for(var i=0;i<rows.length;i++){
            ids += rows[i]["id"];
            if (i < rows.length-1) ids += ",";
        }
        cloneAllGoodses(ids);
    }
}
,
{
    text:'批删除',
    iconCls:'icon-remove',
    handler:function(){
        var rows = $("#dg").datagrid("getChecked");
        if (rows == undefined || rows == null || rows.length == 0 ){
            $.messager.alert("警告","请选定记录！","warning");
            return;
        }
        if ($.messager.confirm("警告","确认要删除选定记录吗？",function(data){
            if (data){
                var ids = "";
                for(var i=0;i<rows.length;i++){
                    ids += rows[i]["id"];
                    if (i < rows.length-1) ids += ",";
                }
                deleteAllGoodses(ids);
            }
        }));
    }
}
,
{
    text:'Excel导出',
    iconCls:'icon-sum',
    handler:function(){
        window.location.href="../goodsController/exportGoodses";
    }
}
,
{
    text:'PDF导出',
    iconCls:'icon-print',
    handler:function(){
        window.location.href="../goodsController/exportGoodsesPDF";
    }
}
,
{
    text:'Word导出',
    iconCls:'icon-save',
    handler:function(){
        window.location.href="../goodsController/exportGoodsesWord";
    }
}
,
{
    text:'PPT导出',
    iconCls:'icon-tip',
    handler:function(){
        window.location.href="../goodsController/exportPPTGoodses";
    }
}
];
$(document).ready(function(){
    checkAccessGoods();
    $("#dg").datagrid("load");
});
function clearForm(formId){
$('#'+formId).form('clear');
}
function addGoods(){
    if ($("#ff").form("validate")) {
        $.ajax({
            type: "post",
            url: "../goodsController/addGoods",
            data: JSON.stringify({
                name:$("#ff").find("#name").val(),
                active:parseBoolean($("#ff").find("input[name='active']:checked").val()),
                cover:$("#ff").find("#cover").val(),
                image1:$("#ff").find("#image1").val(),
                image2:$("#ff").find("#image2").val(),
                price:$("#ff").find("#price").val(),
                intro:$("#ff").find("#intro").val(),
                stock:$("#ff").find("#stock").val(),
                type:$("#ff").find("#type").combobox("getValue"),
                isScroll:parseBoolean($("#ff").find("input[name='isScroll']:checked").val()),
                isHot:parseBoolean($("#ff").find("input[name='isHot']:checked").val()),
                isNew:parseBoolean($("#ff").find("input[name='isNew']:checked").val()),
            }),
            dataType: 'json',
            contentType:"application/json;charset=UTF-8",
            success: function(data, textStatus) {
                if (data.success) {
                    window.location.reload();
                }
                },
            complete : function(XMLHttpRequest, textStatus) {
            },
            error : function(XMLHttpRequest,textStatus,errorThrown) {
                alert("Error:"+textStatus);
                alert(errorThrown.toString());
            }
        });
    }
}

function updateGoods(){
    $.ajax({
        type: "post",
        url: "../goodsController/updateGoods",
        data: JSON.stringify({
            id:$("#ffedit").find("#id").val(),
            name:$("#ffedit").find("#name").val(),
            active:parseBoolean($("#ffedit").find("input[name='active']:checked").val()),
            cover:$("#ffedit").find("#cover").val(),
            image1:$("#ffedit").find("#image1").val(),
            image2:$("#ffedit").find("#image2").val(),
            price:$("#ffedit").find("#price").val(),
            intro:$("#ffedit").find("#intro").val(),
            stock:$("#ffedit").find("#stock").val(),
            type:$("#ffedit").find("#type").combobox("getValue"),
            isScroll:parseBoolean($("#ffedit").find("input[name='isScroll']:checked").val()),
            isHot:parseBoolean($("#ffedit").find("input[name='isHot']:checked").val()),
            isNew:parseBoolean($("#ffedit").find("input[name='isNew']:checked").val()),
        }),
        dataType: 'json',
        contentType:"application/json;charset=UTF-8",
        success: function(data, textStatus) {
            if (data.success){
                $("#wupdateGoods").window('close');
                $("#dg").datagrid("load");
            }
        },
        complete : function(XMLHttpRequest, textStatus) {
        },
        error : function(XMLHttpRequest,textStatus,errorThrown) {
            alert("Error:"+textStatus);
            alert(errorThrown.toString());
        }
    }); 
}

function softDeleteGoods(id){
    $.ajax({
        type: "post",
        url: "../goodsController/softDeleteGoods",
        data: {
            "id":id	
        },
        dataType: 'json',
        success: function(data, textStatus) {
            $("#dg").datagrid("load");
        },
        complete : function(XMLHttpRequest, textStatus) {
        },
        error : function(XMLHttpRequest,textStatus,errorThrown) {
            alert("Error:"+textStatus);
            alert(errorThrown.toString());
        }
    });
}

function activateGoods(id){
    $.ajax({
        type: "post",
        url: "../goodsController/activateGoods",
        data: {
            "id":id
        },
        dataType: 'json',
        success: function(data, textStatus) {
            $("#dg").datagrid("load");
        },
        complete : function(XMLHttpRequest, textStatus) {
        },
        error : function(XMLHttpRequest,textStatus,errorThrown) {
            alert("Error:"+textStatus);
            alert(errorThrown.toString());
        }
    });
}

function cloneGoods(id){
    $.ajax({
        type: "post",
        url: "../goodsController/cloneGoods",
        data: {
            "id":id	
        },
        dataType: 'json',
        success: function(data, textStatus) {
            $("#dg").datagrid("load");
        },
        complete : function(XMLHttpRequest, textStatus) {
        },
        error : function(XMLHttpRequest,textStatus,errorThrown) {
            alert("Error:"+textStatus);
            alert(errorThrown.toString());
        }
    });
}

function deleteGoods(id){
    $.ajax({
        type: "post",
        url: "../goodsController/deleteGoods",
        dataType: 'json',
        data:{"id":id},
        success: function(data, textStatus) {
            $("#dg").datagrid("load");
        },
        complete : function(XMLHttpRequest, textStatus) {
        },
        error : function(XMLHttpRequest,textStatus,errorThrown) {
            alert("Error:"+textStatus);
            alert(errorThrown.toString());
        }
    }); 
}

function toggleGoods(id){
    $.ajax({
        type: "post",
        url: "../goodsController/toggleGoods",
        data: {
            "id":id
        },
        dataType: 'json',
        success: function(data, textStatus) {
            $("#dg").datagrid("load");
        },
        complete : function(XMLHttpRequest, textStatus) {
        },
        error : function(XMLHttpRequest,textStatus,errorThrown) {
            alert("Error:"+textStatus);
            alert(errorThrown.toString());
        }
    });
}

function toggleOneGoods(id){
    $.ajax({
        type: "post",
        url: "../goodsController/toggleOneGoods",
        data: {
            "id":id
        },
        dataType: 'json',
        success: function(data, textStatus) {
            $("#dg").datagrid("load");
        },
        complete : function(XMLHttpRequest, textStatus) {
        },
        error : function(XMLHttpRequest,textStatus,errorThrown) {
            alert("Error:"+textStatus);
            alert(errorThrown.toString());
        }
    });
}

function softDeleteAllGoodses(ids){
    $.ajax({
        type: "post",
            url: "../goodsController/softDeleteAllGoodses",
            data: {
                ids:ids
            },
            dataType: 'json',
            success: function(data, textStatus) {
                $("#dg").datagrid("load");
            },
            complete : function(XMLHttpRequest, textStatus) {
        },
        error : function(XMLHttpRequest,textStatus,errorThrown) {
            alert("Error:"+textStatus);
            alert(errorThrown.toString());
        }
    });
}

function activateAllGoodses(ids){
    $.ajax({
        type: "post",
            url: "../goodsController/activateAllGoodses",
            data: {
                ids:ids
            },
            dataType: 'json',
            success: function(data, textStatus) {
                $("#dg").datagrid("load");
            },
            complete : function(XMLHttpRequest, textStatus) {
        },
        error : function(XMLHttpRequest,textStatus,errorThrown) {
            alert("Error:"+textStatus);
            alert(errorThrown.toString());
        }
    });
}

function cloneAllGoodses(ids){
    $.ajax({
        type: "post",
            url: "../goodsController/cloneAllGoodses",
            data: {
                ids:ids
            },
            dataType: 'json',
            success: function(data, textStatus) {
                $("#dg").datagrid("load");
            },
            complete : function(XMLHttpRequest, textStatus) {
        },
        error : function(XMLHttpRequest,textStatus,errorThrown) {
            alert("Error:"+textStatus);
            alert(errorThrown.toString());
        }
    });
}

function deleteAllGoodses(ids){
    $.ajax({
        type: "post",
        url: "../goodsController/deleteAllGoodses",
        data: {
            ids:ids
        },
        dataType: 'json',
        success: function(data, textStatus) {
            $("#dg").datagrid("load");
        },
        complete : function(XMLHttpRequest, textStatus) {
        },
        error : function(XMLHttpRequest,textStatus,errorThrown) {
            alert("Error:"+textStatus);
            alert(errorThrown.toString());
        }
    });
}

function searchGoodsesByFieldsByPage(){
    params = {
        name:$("#ffsearch").find("#name").val(),
        active:parseBoolean($("#ffsearch").find("#active").val()),
        price:$("#ffsearch").find("#price").val(),
        intro:$("#ffsearch").find("#intro").val(),
        stock:$("#ffsearch").find("#stock").val(),
        type:$("#ffsearch").find("#type").combobox("getValue"),
        isScroll:parseBoolean($("#ffsearch").find("#isScroll").val()),
        isHot:parseBoolean($("#ffsearch").find("#isHot").val()),
        isNew:parseBoolean($("#ffsearch").find("#isNew").val()),
    };
    $("#dg").datagrid({queryParams:params});
}

function filterGoodsesExcel(){
    params = {
        name:$("#ffsearch").find("#name").val(),
        active:parseBoolean($("#ffsearch").find("#active").val()),
        price:$("#ffsearch").find("#price").val(),
        intro:$("#ffsearch").find("#intro").val(),
        stock:$("#ffsearch").find("#stock").val(),
        type:$("#ffsearch").find("#type").combobox("getValue"),
        isScroll:parseBoolean($("#ffsearch").find("#isScroll").val()),
        isHot:parseBoolean($("#ffsearch").find("#isHot").val()),
        isNew:parseBoolean($("#ffsearch").find("#isNew").val()),
    };
    var params0 = $.param(params);
    document.location.href = "../goodsController/filterGoodsesExcel?" + params0;
}

function filterGoodsesPDF(){
    params = {
        name:$("#ffsearch").find("#name").val(),
        active:parseBoolean($("#ffsearch").find("#active").val()),
        price:$("#ffsearch").find("#price").val(),
        intro:$("#ffsearch").find("#intro").val(),
        stock:$("#ffsearch").find("#stock").val(),
        type:$("#ffsearch").find("#type").combobox("getValue"),
        isScroll:parseBoolean($("#ffsearch").find("#isScroll").val()),
        isHot:parseBoolean($("#ffsearch").find("#isHot").val()),
        isNew:parseBoolean($("#ffsearch").find("#isNew").val()),
    };
    var params0 = $.param(params);
    document.location.href = "../goodsController/filterGoodsesPDF?" + params0;
}

function filterGoodsesWord(){
    params = {
        name:$("#ffsearch").find("#name").val(),
        active:parseBoolean($("#ffsearch").find("#active").val()),
        price:$("#ffsearch").find("#price").val(),
        intro:$("#ffsearch").find("#intro").val(),
        stock:$("#ffsearch").find("#stock").val(),
        type:$("#ffsearch").find("#type").combobox("getValue"),
        isScroll:parseBoolean($("#ffsearch").find("#isScroll").val()),
        isHot:parseBoolean($("#ffsearch").find("#isHot").val()),
        isNew:parseBoolean($("#ffsearch").find("#isNew").val()),
    };
    var params0 = $.param(params);
    document.location.href = "../goodsController/filterGoodsesWord?" + params0;
}

function filterPPTGoodses(){
    params = {
        name:$("#ffsearch").find("#name").val(),
        active:parseBoolean($("#ffsearch").find("#active").val()),
        price:$("#ffsearch").find("#price").val(),
        intro:$("#ffsearch").find("#intro").val(),
        stock:$("#ffsearch").find("#stock").val(),
        type:$("#ffsearch").find("#type").combobox("getValue"),
        isScroll:parseBoolean($("#ffsearch").find("#isScroll").val()),
        isHot:parseBoolean($("#ffsearch").find("#isHot").val()),
        isNew:parseBoolean($("#ffsearch").find("#isNew").val()),
    };
    var params0 = $.param(params);
    document.location.href = "../goodsController/filterPPTGoodses?" + params0;
}

function checkAccessGoods(){
    $.ajax({
        type: "get",
        url: "../goodsController/checkAccessGoods",
        dataType: 'json',
        success: function(data, textStatus) {
            if (!data.success && data.noAuth){
                window.location.href="../login/noauth.html"
            }
        },
        complete : function(XMLHttpRequest, textStatus) {
        },
        error : function(XMLHttpRequest,textStatus,errorThrown) {
            alert("Error:"+textStatus);
            alert(errorThrown.toString());
        }
    }); 
}

function parseBoolean(val){
    if (val == undefined|| val == null) return false;
    var isInt = /^(-}+)?\d+$/.test(val);
    if (isInt&& val == "0") return false;
    else if (isInt&& val == "1") return true;
    else if (val.toLowerCase() == "false") return false;
    else if (val.toLowerCase() == "true") return true;
    else if (val.toLowerCase() == "f") return false;
    else if (val.toLowerCase() == "t") return true;
    else if (val.toLowerCase() == "n") return false;
    else if (val.toLowerCase() == "y") return true;
    else if (val.toLowerCase() == "no") return false;
    else if (val.toLowerCase() == "yes") return true;
    else return "";
}

function parseBooleanInt(val){
    var b = parseBoolean(val);
    if (b==undefined||b==null) return 0;
    else if (b==true) return 1;
    else return 0;
}

function isBlank(val){
    if (val == undefined|| val == null || val == "" || val== "0" || val == 0) return true;
    else return false;
}

function checkRadioBoxValue(control,field,fieldvalue){
    var checkboxs = $("#"+control).find("input[name='"+field+"']");
    for (var i=0;i<checkboxs.length;i++){
        if (checkboxs.get(i).value == ""+fieldvalue) checkboxs.get(i).checked=true;
    }
}

function toggleBtnShow(index){
    $('#button-bar a').css('display','none');
    $('#button-bar a:nth-child('+(index)+')').css('display','block');
}

function translateType(value){
    if (isBlank(value)) return "";
    var retVal = value;
    $.ajax({
        type:"post",
        url: "../typeController/findTypeById",
        data: {
            id:value
        },
        dataType: 'json',
        async:false,
        success: function(data, textStatus) {
            debugger;
            if ( data.data !=null && data.data.name!=null){
                retVal = data.data.name;
            }else{
                retVal = "";
            }
        },
        complete : function(XMLHttpRequest, textStatus) {
        },
        error : function(XMLHttpRequest,textStatus,errorThrown) {
            alert("Error:"+textStatus);
            alert(errorThrown.toString());
        }
    });
    return retVal;
}

function showGoodsCoverImage(value,row,index){
    if(row.cover){
        return "<img style='height:50px;' border='1' src='data:image/png;base64,"+row.cover+"'/>";
    } else {
        return "<img style='height:50px;' border='1' src='../css/images/blank.jpg'/>";
    }
}

function showGoodsImage1Image(value,row,index){
    if(row.image1){
        return "<img style='height:50px;' border='1' src='data:image/png;base64,"+row.image1+"'/>";
    } else {
        return "<img style='height:50px;' border='1' src='../css/images/blank.jpg'/>";
    }
}

function showGoodsImage2Image(value,row,index){
    if(row.image2){
        return "<img style='height:50px;' border='1' src='data:image/png;base64,"+row.image2+"'/>";
    } else {
        return "<img style='height:50px;' border='1' src='../css/images/blank.jpg'/>";
    }
}

</script>
</html>
